package com.cly.controller;

import cn.hutool.core.lang.tree.Tree;
import com.cly.base.controller.BaseController;
import com.cly.entity.PostCategory;
import com.cly.result.JsonRequest;
import com.cly.service.IPostCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 岗位分类控制类
 *
 * @author by 春风能解释
 * <p>
 * 2024/11/13
 */
@RestController
@RequestMapping("/postCategory")
@Tag(name = "岗位分类控制类", description = "岗位分类操作访问接口")
public class PostCategoryController extends BaseController<IPostCategoryService, PostCategory> {

    /**
     * 分页查询岗位分类
     *
     * @param current      当前页码
     * @param size         每页显示数量
     * @param postCategory 条件
     * @return JSON
     */
    @GetMapping
    @Operation(summary = "分页查询岗位分类")
    public JsonRequest<List<PostCategory>> getPostCategoryPage(
            @Parameter(description = "页码", required = true)
            @RequestParam Integer current,
            @Parameter(description = "页长", required = true)
            @RequestParam Integer size,
            @Parameter(description = "条件")
            PostCategory postCategory) {
        return baseService.getPostCategoryPage(current, size, postCategory);
    }

    /**
     * 获取岗位分类树形结构
     *
     * @param PostCategory 条件
     * @return 岗位分类树形结构
     */
    @GetMapping("/tree")
    @Operation(summary = "获取岗位分类树形结构")
    public JsonRequest<List<Tree<String>>> getPostCategoryTree(
            @Parameter(description = "分类数据", required = true)
            PostCategory PostCategory) {
        return baseService.getPostCategoryTree(PostCategory);
    }

    /**
     * 新增岗位分类
     *
     * @param postCategory 新增的岗位分类
     * @return JSON
     */
    @PostMapping
    @Operation(summary = "新增岗位")
    public JsonRequest<Boolean> addPostCategory(
            @Parameter(description = "岗位分类数据", required = true)
            @RequestBody PostCategory postCategory) {
        return baseService.addPostCategory(postCategory);
    }

    /**
     * 删除岗位分类
     *
     * @param ids 分类ID
     * @return JSON
     */
    @DeleteMapping
    @Operation(summary = "删除岗位分类")
    public JsonRequest<Boolean> deletePostCategory(
            @Parameter(description = "分类ID", required = true)
            @RequestBody List<Long> ids) {
        return baseService.deletePostCategory(ids);
    }

    /**
     * 修改岗位分类
     *
     * @param postCategory 修改的岗位分类
     * @return JSON
     */
    @PutMapping
    @Operation(summary = "修改岗位分类")
    public JsonRequest<Boolean> updatePostCategory(
            @Parameter(description = "岗位分类")
            @RequestBody PostCategory postCategory) {
        return baseService.updatePostCategory(postCategory);
    }

}
